<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>拖拽</title>
    <style>
        #div1, #div2 {
            float: left;
            width: 400px;
            height: 400px;
            margin: 100px;
            border: 1px solid #000000;
        }
    </style>

    <script>
        function drag(ev) {
            ev.dataTransfer.setData('Text', ev.target.id);
            console.log(ev.target.id);
        }

        function allowDrop(ev) {
            ev.preventDefault();
        }

        function drop(ev) {
            ev.preventDefault();
            let data = ev.dataTransfer.getData('Text');
            ev.target.appendChild(document.getElementById(data));
        }
    </script>
</head>
<body>
    <div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)">
        <!-- draggable可以拖拽 -->
        <img id="img1" src="src/images/1.jpg" draggable="true" ondragstart="drag(event)" />
        <img id="img2" src="src/images/2.jpg" draggable="true" ondragstart="drag(event)" />
    </div>
    <div id="div2" ondrop="drop(event)" ondragover="allowDrop(event)">

    </div>
</body>
</html>